﻿namespace ExamV5.Persion
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class ExamHistoryList : Page
    {
        protected Button butQuery;
        protected GridView DataGridInfo;
        protected DropDownList DDLQuery;
        protected DropDownList DDLSubject;
        protected HtmlForm Form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Label labRescordCount;
        protected LinkButton LBFirstPage;
        protected LinkButton LBLastPage;
        protected LinkButton LBNextPage;
        protected LinkButton LBPrevPage;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        private string string_0 = "";
        private string string_1 = "";
        protected TextBox txtEndDate;
        protected TextBox txtQuery;
        protected TextBox txtStartDate;
        protected UpdatePanel UPPart;

        protected void butQuery_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void DataGridInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.DataGridInfo.PageIndex = e.NewPageIndex;
            this.method_0();
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItemIndex == -1)
            {
                this.DataGridInfo.Attributes.Add("oldValue", "#FFFFFF");
                this.DataGridInfo.Attributes.Add("singleValue", "#FFFFFF");
            }
            else
            {
                e.Row.Attributes.Add("onmouseover", "this.bgColor='#F6F5F5'");
                if ((e.Row.DataItemIndex % 2) != 0)
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('oldValue')");
                }
                else
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('singleValue')");
                }
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[0].Text.Length > Convert.ToInt32(this.ViewState["SubStrLen"].ToString()))
                {
                    e.Row.Cells[0].Text = "<a title=" + e.Row.Cells[0].Text + ">" + e.Row.Cells[0].Text.Substring(0, Convert.ToInt32(this.ViewState["SubStrLen"].ToString())) + "…</a>";
                }
                if (e.Row.Cells[1].Text.Length > 10)
                {
                    e.Row.Cells[1].Text = "<a title=" + e.Row.Cells[1].Text + ">" + e.Row.Cells[1].Text.Substring(0, 10) + "…</a>";
                }
                LinkButton button = (LinkButton) e.Row.Cells[8].FindControl("LBSubmit");
                Label label = (Label) e.Row.Cells[7].FindControl("labLook");
                string str4 = "";
                if (!(this.ViewState["UserPower"].ToString() == "Y"))
                {
                    str4 = " title='查看考卷权限暂未开放'";
                }
                else
                {
                    string values = this.publicFun_0.GetValues("select LookPaperID from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "LookPaperID");
                    if (!(values.Trim() != ""))
                    {
                        str4 = "href='FrmLookPaper.aspx?UserCode=" + base.Server.UrlEncode(this.httpCookie_0.Value) + "&PaperID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString() + "' title='查看考卷详细批改信息'";
                    }
                    else if (values.Trim().IndexOf("," + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString() + ",") < 0)
                    {
                        str4 = " title='查看考卷权限暂未开放'";
                    }
                    else
                    {
                        str4 = "href='FrmLookPaper.aspx?UserCode=" + base.Server.UrlEncode(this.httpCookie_0.Value) + "&PaperID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString() + "' title='查看考卷详细批改信息'";
                    }
                    if ((str4.Length > 0x19) && ((this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='LookPaperFlag'", "ParmValue").Trim().Trim() == "N") && (e.Row.Cells[4].Text.Trim() != "考试批改完成")))
                    {
                        str4 = " title='查看考卷权限暂未开放'";
                    }
                }
                if (!(this.string_0 == "Y"))
                {
                    button.Enabled = false;
                    button.ToolTip = "未通开或超过重考次数";
                    button.ForeColor = Color.Gray;
                }
                else
                {
                    int num4 = Convert.ToInt16(this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperJoinNum"].ToString());
                    int num3 = Convert.ToInt16(this.DataGridInfo.DataKeys[e.Row.RowIndex]["ExamJoinNum"].ToString());
                    if (num3 >= num4)
                    {
                        button.Enabled = false;
                        button.ToolTip = "未通开或超过重考次数";
                        button.ForeColor = Color.Gray;
                    }
                    else
                    {
                        button.Enabled = true;
                        button.Attributes.Add("onclick", "javascript:{if(confirm('重考次数为【" + num3.ToString() + "／" + num4.ToString() + "】重考后之前成绩清零，确定要重考吗？')==false) return false;}");
                        button.Text = "<font color=red>重考</font>";
                    }
                }
                double num2 = Convert.ToDouble(e.Row.Cells[5].Text.Trim());
                if (!(this.ViewState["IsGradeLook"].ToString() == "N"))
                {
                    label.Text = "<a " + str4 + " Target='_blank'>查卷</a>";
                }
                else
                {
                    e.Row.Cells[5].Text = "";
                }
                if (!(!(this.string_1 == "") ? !(this.string_1 == "Y") : false))
                {
                    string str3 = this.publicFun_0.GetValues(string.Concat(new object[] { "select ReuleName from GradeReule where PaperID=", this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString(), " and MinValue<=", num2, " and ", num2, "<=MaxValue" }), "ReuleName");
                    if (str3.Trim() == "")
                    {
                        str3 = this.publicFun_0.GetValues(string.Concat(new object[] { "select ReuleName from GradeReule where PaperID=0 and MinValue<=", num2, " and ", num2, "<=MaxValue" }), "ReuleName");
                        if (str3.Trim() == "")
                        {
                            str3 = "未定义";
                        }
                    }
                    e.Row.Cells[5].Text = e.Row.Cells[5].Text + "<font color=red>(" + str3 + ")</font>";
                }
                if (this.ViewState["IsGradeSort"].ToString() != "N")
                {
                    e.Row.Cells[6].Text = this.method_1(this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString());
                }
                if (this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsAllowPrint'", "ParmValue").Trim().Trim() != "N")
                {
                    label.Text = label.Text + "&nbsp;<a href='#' onclick=javascript:PrintInfo('" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString() + "','" + base.Server.UrlEncode(this.httpCookie_0.Value) + "');>打印</a>";
                }
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                if (this.ViewState["SortType"].ToString() == " Desc")
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "ExamName":
                            e.Row.Cells[0].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "SubjectName":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "PaperFen":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "JoinDate":
                            e.Row.Cells[3].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "FlagInfo":
                            e.Row.Cells[4].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "GetCountFen":
                            e.Row.Cells[5].Controls.Add(new LiteralControl("↑"));
                            return;
                    }
                    e.Row.Cells[3].Controls.Add(new LiteralControl("↑"));
                }
                else
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "ExamName":
                            e.Row.Cells[0].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "SubjectName":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "PaperFen":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "JoinDate":
                            e.Row.Cells[3].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "FlagInfo":
                            e.Row.Cells[4].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "GetCountFen":
                            e.Row.Cells[5].Controls.Add(new LiteralControl("↓"));
                            return;
                    }
                    e.Row.Cells[3].Controls.Add(new LiteralControl("↓"));
                }
            }
        }

        protected void DataGridInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string str = this.publicFun_0.CheckString(this.DataGridInfo.DataKeys[e.RowIndex]["PaperID"].ToString());
            string connectionString = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
            string str3 = "";
            string str4 = "";
            string str5 = "";
            string str6 = "";
            string str7 = "";
            string str8 = "";
            SqlConnection connection = new SqlConnection(connectionString);
            connection.Open();
            SqlCommand command = new SqlCommand("select a.PaperEndTime,a.ExamName,a.PaperStatus,a.RubricDist,a.SubjectID,a.SubjectName,a.PaperDiff,a.ExamTime from PaperInfo a where  a.ID=" + str, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                str3 = reader["RubricDist"].ToString();
                str4 = reader["SubjectID"].ToString();
                reader["SubjectName"].ToString();
                str5 = reader["PaperDiff"].ToString();
                str6 = reader["PaperStatus"].ToString();
                reader["ExamName"].ToString();
                str7 = reader["ExamTime"].ToString();
                str8 = reader["PaperEndTime"].ToString();
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            if (DateTime.Now > Convert.ToDateTime(str8))
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BEnterAATip", "alert('试卷有效期已过，无法设置重考！')", true);
            }
            else
            {
                string strSql = "";
                string str13 = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='RExamPaperType'", "ParmValue").Trim();
                if (!(str13.Trim() == "") ? !(str13.Trim() == "Y") : false)
                {
                    string[] strArray = str4.Split(new char[] { ',' });
                    string str11 = "";
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        if (str11.Trim().Length != 0)
                        {
                            str11 = str11 + " or SubjectID='" + strArray[i].Trim() + "'";
                        }
                        else
                        {
                            str11 = "SubjectID='" + strArray[i].Trim() + "'";
                        }
                    }
                    try
                    {
                        string str9 = "";
                        if (!(this.publicFun_0.GetValues("select PaperID from PaperRule where PaperID=" + str, "PaperID") != ""))
                        {
                            str9 = "A";
                        }
                        else
                        {
                            str9 = "B";
                        }
                        if (str9.Trim() == "A")
                        {
                            this.method_2(str, str3.Trim(), str11, str5, str6, str7);
                        }
                        if (str9.Trim() == "B")
                        {
                            string str10 = "select ID from RubricInfo where IsDel='N' and Flag='" + str6 + "' and ISCheck='N'";
                            this.method_3(str, str10, str3, str7);
                        }
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BEnterTip", "alert('设置重考并生成新试卷信息成功！');setTimeout(function(){window.location='../LineStudyExam/ExamInfoList.aspx'},500);", true);
                    }
                    catch
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BEnterTip", "alert('设置重考并生成新试卷信息失败！');", true);
                    }
                }
                else
                {
                    strSql = "update ExamUser set LastTime='" + str7 + "',Flag='A',IsSave=0,StartTime='',EndTime='',GetOldCountFen=0,GetCountFen=0,LoginIP='' where UserCode='" + this.httpCookie_0.Value + "' and PaperID=" + str + ";delete from CheckPaper where  UserCode='" + this.httpCookie_0.Value + "' and PaperID=" + str;
                    this.publicFun_0.ExecuteSql(strSql);
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BEnterTip", "alert('设置重考并生成新试卷信息成功！');setTimeout(function(){window.location='../LineStudyExam/ExamInfoList.aspx'},500)", true);
                }
                this.DataGridInfo.PageIndex = 0;
                this.method_0();
            }
        }

        protected void DataGridInfo_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sortExpression = e.SortExpression;
            if (this.ViewState["SortFiled"].ToString() == sortExpression)
            {
                if (this.ViewState["SortType"].ToString() == " Desc")
                {
                    this.ViewState["SortType"] = " ASC";
                }
                else
                {
                    this.ViewState["SortType"] = " Desc";
                }
            }
            else
            {
                this.ViewState["SortFiled"] = e.SortExpression;
            }
            this.method_0();
        }

        protected void DDLSubject_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void LBFirstPage_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void LBLastPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageCount > 0)
            {
                this.DataGridInfo.PageIndex = this.DataGridInfo.PageCount - 1;
                this.method_0();
            }
        }

        protected void LBNextPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex < (this.DataGridInfo.PageCount - 1))
            {
                this.DataGridInfo.PageIndex++;
                this.method_0();
            }
        }

        protected void LBPrevPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex > 0)
            {
                this.DataGridInfo.PageIndex--;
                this.method_0();
            }
        }

        private void method_0()
        {
            string selectCommandText = "select b.JoinExamNum as PaperJoinNum,a.JoinExamNum as ExamJoinNum,'0' as SortInfo,a.JoinDate,b.PaperFen,a.PaperID,a.ExamName,b.SubjectName,a.StartTime,a.EndTime,ROUND(a.GetCountFen,2) as GetCountFen,FlagInfo=case a.Flag when 'C' then '考试完成' when 'D' then '客观题批改完成' when 'E' then '考试批改完成' when 'G' then '考试异常'  when 'Z' then '作弊标记' end  from ExamUser a,PaperInfo b where a.PaperID=b.ID and (a.Flag<>'A' and a.Flag<>'B') and a.ExamType='A' and a.UserCode='" + this.httpCookie_0.Value + "'";
            if (this.DDLSubject.SelectedItem.Value != "0")
            {
                selectCommandText = selectCommandText + " and b.SubjectName like '%" + this.publicFun_0.CheckString(this.DDLSubject.SelectedItem.Text.Replace("│", "").Replace("├", "")) + "%'";
            }
            if (this.txtQuery.Text.Trim() != "")
            {
                selectCommandText = selectCommandText + " and " + this.publicFun_0.CheckString(this.DDLQuery.SelectedItem.Value) + " like '%" + this.publicFun_0.CheckString(this.txtQuery.Text) + "%'";
            }
            if ((this.txtStartDate.Text != "") && (this.txtEndDate.Text != ""))
            {
                selectCommandText = selectCommandText + " and (a.JoinDate>=Convert(DateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text) + "') and a.JoinDate<=Convert(DateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text) + "'))";
            }
            selectCommandText = selectCommandText + " order by " + this.ViewState["SortFiled"].ToString() + this.ViewState["SortType"].ToString();
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "DataInfo");
            this.DataGridInfo.DataSource = dataSet.Tables["DataInfo"].DefaultView;
            this.DataGridInfo.DataBind();
            this.labRescordCount.Text = "总共&nbsp;<font color='#0000C0'><b>" + dataSet.Tables["DataInfo"].Rows.Count.ToString() + "</b></font>&nbsp;条记录&nbsp;<font color='#0000C0'><b>" + Convert.ToString((int) (this.DataGridInfo.PageIndex + 1)) + "/" + this.DataGridInfo.PageCount.ToString() + "</b></font>&nbsp;页&nbsp;";
            adapter.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
        }

        private string method_1(string string_2)
        {
            string str = "0";
            int num = 0;
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand("select * from ExamUser where PaperID=" + string_2 + " and  (Flag<>'A' and Flag<>'B') order by GetCountFen desc", connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                num++;
                if (reader["UserCode"].ToString().Trim() == this.httpCookie_0.Value)
                {
                    str = num.ToString();
                }
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            return str;
        }

        private void method_2(string string_2, string string_3, string string_4, string string_5, string string_6, string string_7)
        {
            string str = "#";
            string str2 = "#";
            string str3 = "#";
            string str4 = "#";
            string str5 = "#";
            string str6 = "#";
            string str7 = "#";
            string str8 = "#";
            string str9 = "#";
            Random random = new Random();
            bool flag = true;
            string[] strArray = string_3.Split(new char[] { '#' });
            string str10 = string_6;
            string strSql = "select ID from RubricInfo where IsDel='N' and Flag='" + str10 + "' and ISCheck='N' and (" + string_4 + ")";
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            DataSet dataSet = new DataSet();
            if (Convert.ToInt32(strArray[0]) > 0)
            {
                int num25 = Convert.ToInt32(strArray[0]);
                SqlDataAdapter adapter9 = new SqlDataAdapter(strSql + " and RubricType='A'", selectConnection);
                adapter9.Fill(dataSet, "AExamData");
                int count = dataSet.Tables["AExamData"].Rows.Count;
                while (flag)
                {
                    if (num25 == 0)
                    {
                        break;
                    }
                    int num27 = random.Next(count);
                    string str30 = dataSet.Tables["AExamData"].Rows[num27]["ID"].ToString() + "#";
                    if (str.IndexOf("#" + str30, 0) == -1)
                    {
                        str = str + str30;
                        num25--;
                    }
                }
                dataSet.Tables.Clear();
                adapter9.Dispose();
            }
            if (Convert.ToInt32(strArray[1]) > 0)
            {
                int num22 = Convert.ToInt32(strArray[1]);
                SqlDataAdapter adapter8 = new SqlDataAdapter(strSql + " and RubricType='B'", selectConnection);
                adapter8.Fill(dataSet, "BExamData");
                int maxValue = dataSet.Tables["BExamData"].Rows.Count;
                while (flag)
                {
                    if (num22 == 0)
                    {
                        break;
                    }
                    int num24 = random.Next(maxValue);
                    string str28 = dataSet.Tables["BExamData"].Rows[num24]["ID"].ToString() + "#";
                    if (str2.IndexOf("#" + str28, 0) == -1)
                    {
                        str2 = str2 + str28;
                        num22--;
                    }
                }
                dataSet.Tables.Clear();
                adapter8.Dispose();
            }
            if (Convert.ToInt32(strArray[2]) > 0)
            {
                int num19 = Convert.ToInt32(strArray[2]);
                SqlDataAdapter adapter7 = new SqlDataAdapter(strSql + " and RubricType='C'", selectConnection);
                adapter7.Fill(dataSet, "CExamData");
                int num20 = dataSet.Tables["CExamData"].Rows.Count;
                while (flag)
                {
                    if (num19 == 0)
                    {
                        break;
                    }
                    int num21 = random.Next(num20);
                    string str26 = dataSet.Tables["CExamData"].Rows[num21]["ID"].ToString() + "#";
                    if (str3.IndexOf("#" + str26, 0) == -1)
                    {
                        str3 = str3 + str26;
                        num19--;
                    }
                }
                dataSet.Tables.Clear();
                adapter7.Dispose();
            }
            if (Convert.ToInt32(strArray[3]) > 0)
            {
                int num16 = Convert.ToInt32(strArray[3]);
                SqlDataAdapter adapter6 = new SqlDataAdapter(strSql + " and RubricType='D'", selectConnection);
                adapter6.Fill(dataSet, "DExamData");
                int num17 = dataSet.Tables["DExamData"].Rows.Count;
                while (flag)
                {
                    if (num16 == 0)
                    {
                        break;
                    }
                    int num18 = random.Next(num17);
                    string str24 = dataSet.Tables["DExamData"].Rows[num18]["ID"].ToString() + "#";
                    if (str4.IndexOf("#" + str24, 0) == -1)
                    {
                        str4 = str4 + str24;
                        num16--;
                    }
                }
                dataSet.Tables.Clear();
                adapter6.Dispose();
            }
            if (Convert.ToInt32(strArray[4]) > 0)
            {
                int num13 = Convert.ToInt32(strArray[4]);
                SqlDataAdapter adapter5 = new SqlDataAdapter(strSql + " and RubricType='E'", selectConnection);
                adapter5.Fill(dataSet, "EExamData");
                int num14 = dataSet.Tables["EExamData"].Rows.Count;
                while (flag)
                {
                    if (num13 == 0)
                    {
                        break;
                    }
                    int num15 = random.Next(num14);
                    string str22 = dataSet.Tables["EExamData"].Rows[num15]["ID"].ToString() + "#";
                    if (str5.IndexOf("#" + str22, 0) == -1)
                    {
                        str5 = str5 + str22;
                        num13--;
                    }
                }
                dataSet.Tables.Clear();
                adapter5.Dispose();
            }
            if (Convert.ToInt32(strArray[5]) > 0)
            {
                int num10 = Convert.ToInt32(strArray[5]);
                SqlDataAdapter adapter4 = new SqlDataAdapter(strSql + " and RubricType='F'", selectConnection);
                adapter4.Fill(dataSet, "FExamData");
                int num11 = dataSet.Tables["FExamData"].Rows.Count;
                while (flag)
                {
                    if (num10 == 0)
                    {
                        break;
                    }
                    int num12 = random.Next(num11);
                    string str20 = dataSet.Tables["FExamData"].Rows[num12]["ID"].ToString() + "#";
                    if (str6.IndexOf("#" + str20, 0) == -1)
                    {
                        str6 = str6 + str20;
                        num10--;
                    }
                }
                dataSet.Tables.Clear();
                adapter4.Dispose();
            }
            if (Convert.ToInt32(strArray[6]) > 0)
            {
                int num7 = Convert.ToInt32(strArray[6]);
                SqlDataAdapter adapter3 = new SqlDataAdapter(strSql + " and RubricType='G'", selectConnection);
                adapter3.Fill(dataSet, "GExamData");
                int num8 = dataSet.Tables["GExamData"].Rows.Count;
                while (flag)
                {
                    if (num7 == 0)
                    {
                        break;
                    }
                    int num9 = random.Next(num8);
                    string str18 = dataSet.Tables["GExamData"].Rows[num9]["ID"].ToString() + "#";
                    if (str7.IndexOf("#" + str18, 0) == -1)
                    {
                        str7 = str7 + str18;
                        num7--;
                    }
                }
                dataSet.Tables.Clear();
                adapter3.Dispose();
            }
            if (Convert.ToInt32(strArray[7]) > 0)
            {
                int num4 = Convert.ToInt32(strArray[7]);
                SqlDataAdapter adapter2 = new SqlDataAdapter(strSql + " and RubricType='H'", selectConnection);
                adapter2.Fill(dataSet, "HExamData");
                int num5 = dataSet.Tables["HExamData"].Rows.Count;
                while (flag)
                {
                    if (num4 == 0)
                    {
                        break;
                    }
                    int num6 = random.Next(num5);
                    string str16 = dataSet.Tables["HExamData"].Rows[num6]["ID"].ToString() + "#";
                    if (str8.IndexOf("#" + str16, 0) == -1)
                    {
                        str8 = str8 + str16;
                        num4--;
                    }
                }
                dataSet.Tables.Clear();
                adapter2.Dispose();
            }
            if (Convert.ToInt32(strArray[8]) > 0)
            {
                int num = Convert.ToInt32(strArray[8]);
                SqlDataAdapter adapter = new SqlDataAdapter(strSql + " and RubricType='I'", selectConnection);
                adapter.Fill(dataSet, "IExamData");
                int num2 = dataSet.Tables["IExamData"].Rows.Count;
                while (flag)
                {
                    if (num == 0)
                    {
                        break;
                    }
                    int num3 = random.Next(num2);
                    string str14 = dataSet.Tables["IExamData"].Rows[num3]["ID"].ToString() + "#";
                    if (str9.IndexOf("#" + str14, 0) == -1)
                    {
                        str9 = str9 + str14;
                        num--;
                    }
                }
                dataSet.Tables.Clear();
                adapter.Dispose();
            }
            dataSet.Clear();
            dataSet.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
            string values = this.publicFun_0.GetValues("select top 1 RubricJ from PaperData where PaperID=" + string_2, "RubricJ");
            if (!(values != ""))
            {
                values = "";
            }
            else
            {
                values = values.Trim().Replace("_", "#");
            }
            if (str.Length <= 1)
            {
                str = "";
            }
            else
            {
                str = str.Substring(1);
            }
            if (str2.Length > 1)
            {
                str2 = str2.Substring(1);
            }
            else
            {
                str2 = "";
            }
            if (str3.Length <= 1)
            {
                str3 = "";
            }
            else
            {
                str3 = str3.Substring(1);
            }
            if (str4.Length <= 1)
            {
                str4 = "";
            }
            else
            {
                str4 = str4.Substring(1);
            }
            if (str5.Length <= 1)
            {
                str5 = "";
            }
            else
            {
                str5 = str5.Substring(1);
            }
            if (str6.Length > 1)
            {
                str6 = str6.Substring(1);
            }
            else
            {
                str6 = "";
            }
            if (str7.Length <= 1)
            {
                str7 = "";
            }
            else
            {
                str7 = str7.Substring(1);
            }
            if (str8.Length <= 1)
            {
                str8 = "";
            }
            else
            {
                str8 = str8.Substring(1);
            }
            if (str9.Length <= 1)
            {
                str9 = "";
            }
            else
            {
                str9 = str9.Substring(1);
            }
            strSql = "update ExamUser set LastTime='" + string_7 + "',Flag='A',IsSave=0,StartTime='',EndTime='',GetOldCountFen=0,GetCountFen=0,LoginIP='' where UserCode='" + this.httpCookie_0.Value + "' and PaperID=" + string_2;
            strSql = strSql + ";update PaperData set RubricS='" + str + "',RubricD='" + str2 + "',RubricB='" + str3 + "',RubricF='" + str4 + "',RubricA='" + str5 + "',RubricC='" + str6 + "',RubricT='" + str7 + "',RubricAN='" + str8 + "',RubricO='" + str9 + "',RubricJ='" + values + "' where PaperID='" + string_2 + "' and UserCode='" + this.httpCookie_0.Value + "'";
            strSql = strSql + ";delete from CheckPaper where  UserCode='" + this.httpCookie_0.Value + "' and PaperID=" + string_2;
            this.publicFun_0.ExecuteSql(strSql);
        }

        private void method_3(string string_2, string string_3, string string_4, string string_5)
        {
            SqlDataReader reader;
            SqlCommand command;
            SqlConnection connection2;
            string str14;
            int count;
            int num3;
            string str = "#";
            string str2 = "#";
            string str3 = "#";
            string str4 = "#";
            string str5 = "#";
            string str6 = "#";
            string str7 = "#";
            string str8 = "#";
            string str9 = "#";
            Random random = new Random();
            bool flag = true;
            string str10 = "";
            int num = 0;
            string[] strArray = string_4.Split(new char[] { '#' });
            string strSql = "";
            string connectionString = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
            SqlConnection selectConnection = new SqlConnection(connectionString);
            DataSet dataSet = new DataSet();
            if (Convert.ToInt32(strArray[0]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_2 + " and RubricType='A'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter9 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter9 = new SqlDataAdapter(string_3 + "  and (" + str10 + ")", selectConnection);
                    adapter9.Fill(dataSet, "AExamData");
                    count = dataSet.Tables["AExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["AExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str.IndexOf("#" + str14, 0) == -1)
                        {
                            str = str + str14;
                            num--;
                        }
                    }
                    adapter9.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[1]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_2 + " and RubricType='B'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter8 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter8 = new SqlDataAdapter(string_3 + " and (" + str10 + ")", selectConnection);
                    adapter8.Fill(dataSet, "BExamData");
                    count = dataSet.Tables["BExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["BExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str2.IndexOf("#" + str14, 0) == -1)
                        {
                            str2 = str2 + str14;
                            num--;
                        }
                    }
                    adapter8.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[2]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_2 + " and RubricType='C'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter7 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter7 = new SqlDataAdapter(string_3 + " and (" + str10 + ")", selectConnection);
                    adapter7.Fill(dataSet, "CExamData");
                    count = dataSet.Tables["CExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["CExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str3.IndexOf("#" + str14, 0) == -1)
                        {
                            str3 = str3 + str14;
                            num--;
                        }
                    }
                    adapter7.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[3]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_2 + " and RubricType='D'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter6 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter6 = new SqlDataAdapter(string_3 + " and (" + str10 + ")", selectConnection);
                    adapter6.Fill(dataSet, "DExamData");
                    count = dataSet.Tables["DExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["DExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str4.IndexOf("#" + str14, 0) == -1)
                        {
                            str4 = str4 + str14;
                            num--;
                        }
                    }
                    adapter6.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[4]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_2 + " and RubricType='E'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter5 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter5 = new SqlDataAdapter(string_3 + " and (" + str10 + ")", selectConnection);
                    adapter5.Fill(dataSet, "EExamData");
                    count = dataSet.Tables["EExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["EExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str5.IndexOf("#" + str14, 0) == -1)
                        {
                            str5 = str5 + str14;
                            num--;
                        }
                    }
                    adapter5.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[5]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_2 + " and RubricType='F'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter4 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter4 = new SqlDataAdapter(string_3 + " and (" + str10 + ")", selectConnection);
                    adapter4.Fill(dataSet, "FExamData");
                    count = dataSet.Tables["FExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["FExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str6.IndexOf("#" + str14, 0) == -1)
                        {
                            str6 = str6 + str14;
                            num--;
                        }
                    }
                    adapter4.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[6]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_2 + " and RubricType='G'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter3 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter3 = new SqlDataAdapter(string_3 + " and (" + str10 + ")", selectConnection);
                    adapter3.Fill(dataSet, "GExamData");
                    count = dataSet.Tables["GExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["GExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str7.IndexOf("#" + str14, 0) == -1)
                        {
                            str7 = str7 + str14;
                            num--;
                        }
                    }
                    adapter3.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[7]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_2 + " and RubricType='H'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter2 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter2 = new SqlDataAdapter(string_3 + " and (" + str10 + ")", selectConnection);
                    adapter2.Fill(dataSet, "HExamData");
                    count = dataSet.Tables["HExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["HExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str8.IndexOf("#" + str14, 0) == -1)
                        {
                            str8 = str8 + str14;
                            num--;
                        }
                    }
                    adapter2.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[8]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_2 + " and RubricType='I'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter = new SqlDataAdapter(string_3 + " and (" + str10 + ")", selectConnection);
                    adapter.Fill(dataSet, "IExamData");
                    count = dataSet.Tables["IExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["IExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str9.IndexOf("#" + str14, 0) == -1)
                        {
                            str9 = str9 + str14;
                            num--;
                        }
                    }
                    adapter.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            dataSet.Clear();
            dataSet.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
            string values = this.publicFun_0.GetValues("select top 1 RubricJ from PaperData where PaperID=" + string_2, "RubricJ");
            if (values != "")
            {
                values = values.Trim().Replace("_", "#");
            }
            else
            {
                values = "";
            }
            if (str.Length <= 1)
            {
                str = "";
            }
            else
            {
                str = str.Substring(1);
            }
            if (str2.Length > 1)
            {
                str2 = str2.Substring(1);
            }
            else
            {
                str2 = "";
            }
            if (str3.Length > 1)
            {
                str3 = str3.Substring(1);
            }
            else
            {
                str3 = "";
            }
            if (str4.Length <= 1)
            {
                str4 = "";
            }
            else
            {
                str4 = str4.Substring(1);
            }
            if (str5.Length <= 1)
            {
                str5 = "";
            }
            else
            {
                str5 = str5.Substring(1);
            }
            if (str6.Length > 1)
            {
                str6 = str6.Substring(1);
            }
            else
            {
                str6 = "";
            }
            if (str7.Length > 1)
            {
                str7 = str7.Substring(1);
            }
            else
            {
                str7 = "";
            }
            if (str8.Length <= 1)
            {
                str8 = "";
            }
            else
            {
                str8 = str8.Substring(1);
            }
            if (str9.Length > 1)
            {
                str9 = str9.Substring(1);
            }
            else
            {
                str9 = "";
            }
            strSql = "update ExamUser set LastTime='" + string_5 + "',Flag='A',IsSave=0,StartTime='',EndTime='',GetOldCountFen=0,GetCountFen=0,LoginIP='' where UserCode='" + this.httpCookie_0.Value + "' and PaperID=" + string_2;
            strSql = strSql + ";update PaperData set RubricS='" + str + "',RubricD='" + str2 + "',RubricB='" + str3 + "',RubricF='" + str4 + "',RubricA='" + str5 + "',RubricC='" + str6 + "',RubricT='" + str7 + "',RubricAN='" + str8 + "',RubricO='" + str9 + "',RubricJ='" + values + "' where PaperID='" + string_2 + "' and UserCode='" + this.httpCookie_0.Value + "'";
            strSql = strSql + ";delete from CheckPaper where  UserCode='" + this.httpCookie_0.Value + "' and PaperID=" + string_2;
            this.publicFun_0.ExecuteSql(strSql);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if (!((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                base.Response.Expires = 0;
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.string_0 = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsSetReExam'", "ParmValue").Trim();
                this.string_1 = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsGradeStand'", "ParmValue").Trim();
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        this.ViewState["UserPower"] = this.publicFun_0.GetValues("select LookPaper from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "LookPaper");
                        this.txtQuery.Attributes.Add("onkeydown", "SubmitKeyClick('butQuery');");
                        this.ViewState["SortFiled"] = " Convert(dateTime,JoinDate)";
                        this.ViewState["SortType"] = " Desc";
                        this.publicFun_0.LoadSubjectInfo(this.DDLSubject, this.httpCookie_0.Value, "N", "B", this.httpCookie_3.Value);
                        this.DDLSubject.Items.Insert(0, new ListItem("--所有科目信息--", "0"));
                        this.ViewState["IsGradeSort"] = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsGradeSort'", "ParmValue").Trim();
                        if (this.ViewState["IsGradeSort"].ToString() == "N")
                        {
                            this.DataGridInfo.Columns[6].Visible = false;
                        }
                        this.ViewState["IsGradeLook"] = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsGradeLook'", "ParmValue").Trim();
                        string str = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='SubStrLength'", "ParmValue").Trim();
                        if (str.Trim() == "")
                        {
                            str = "20";
                        }
                        this.ViewState["SubStrLen"] = str;
                        this.method_0();
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请与管理员联系！')", true);
                    }
                }
            }
        }
    }
}

